/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import MatrizDinamica.Matriz;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import negocio.Prenda;
import negocio.Prendas;

/**
 *
 * @author pablo
 */
public class BuscarLavenderia extends javax.swing.JInternalFrame {

    Object[] namecolums = {"IdPrenda", "Nombre", "Foto", "Fecha de Envio", "Dias Restantes"};
    DefaultTableModel temp = new DefaultTableModel(namecolums, 0);
    Prendas prendas = new Prendas();
    Prenda prenda = new Prenda();
    private int row;
    Validacion valida = new Validacion();

    public BuscarLavenderia() {
        initComponents();
        jTable1.setModel(temp);
        Actualizar();
    }

    public void Actualizar() {
        Matriz m = new Matriz(5);
        ArrayList listaprendas = new ArrayList();
        prendas.listar3();
        listaprendas = prendas.getPrendas();
        for (int i = 0; i < listaprendas.size(); i++) {
            Prenda aux = new Prenda();
            aux = (Prenda) listaprendas.get(i);
            Object nuevo[] = {aux.getCodigo(), aux.getNombre(), aux.getFoto(), aux.getFechalav(), aux.getDias()};
            m.agregar(nuevo);
        }
        temp.setDataVector(m.darTablaEntera(), namecolums);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jbponerdisponible = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();

        setTitle("Búsqueda de ropa en Lavandería");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jbponerdisponible.setText("Reingresar Prenda  ");
        jbponerdisponible.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbponerdisponibleActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 255));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Busqueda de ropa En Lavanderia");
        jLabel2.setToolTipText("");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jbponerdisponible)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbponerdisponible, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbponerdisponibleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbponerdisponibleActionPerformed
        if (row != -1) {
            prenda.ponerDisponible((int) jTable1.getValueAt(0, row));
            Actualizar();
        } else {
            valida.mensaje("Selecione Primero Una Prenda", 2);
        }
    }//GEN-LAST:event_jbponerdisponibleActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        row = jTable1.getSelectedRow();

    }//GEN-LAST:event_jTable1MouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jbponerdisponible;
    // End of variables declaration//GEN-END:variables
}
